package org.ycty.deale;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.ycty.dao.HibernateSessionFactory;
import org.ycty.entity.Imgs;
import org.ycty.entity.Swt;

public class ImgsDeale {
	public List getimgs() {
		return HibernateSessionFactory.getSession().createQuery("from Imgs")
				.list();
	}

	public Boolean deleImg(int id) {
		Boolean b = true;
		Session session = HibernateSessionFactory.getSession();
		Transaction tc = null;

		try {
			tc = session.beginTransaction();
			Imgs imgs = (Imgs) session.get(Imgs.class, id);
			session.delete(imgs);
			tc.commit();
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			b = false;
			e.printStackTrace();
		}
		return b;
	}

	public Boolean addORupImg(Imgs imgs) {
		Boolean b = true;
		Session session = HibernateSessionFactory.getSession();
		Transaction tc = null;

		try {
			tc = session.beginTransaction();
			session.saveOrUpdate(imgs);
			tc.commit();
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			b = false;
			e.printStackTrace();
		}
		return b;
	}

	public Imgs getOne(int id) {
		return (Imgs) HibernateSessionFactory.getSession().createQuery(
				"from Imgs where id=?").setInteger(0, id).uniqueResult();

	}
}
